<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 头部操作栏 -->
            <div class="layui-form lay-header">
                <div class="toolbar">
                    <div class="layui-form-item lay-query-content">
                        <div class="lay-query-box">
                            <div class="query-lt">
                                <div class="layui-inline">
                                    <label class="layui-form-label">供应商名称:</label>
                                    <div class="layui-input-inline">
                                        <input type="text" class="layui-input" name="corporateName" placeholder="供应商名称" autocomplete="off"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog" lay-submit layui-form-keyDownSearch="true">查询</button>
                                    <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>重置</button>
                                </div>
                            </div>
                            <div class="query-rt"></div>
                        </div>
                    </div>
                </div>
                <div class="lay-btn-rows">
                    <div class="lay-btn-box">
                        <div class="lay-btn-lt">
                            <button id="supplierInfoBtnAdd" class="layui-btn icon-btn color-reseda">添加</button>
                        </div>
                        <div class="lay-btn-rt">
                        </div>
                    </div>
                </div>
            </div>
            <!-- 表格 -->
            <table class="layui-table" id="supplierInfoTable" lay-filter="supplierInfoTable"></table>
        </div>
    </div>
</div>

<style>
    div[lay-id="agentAddDueTable"] .layui-table-box,
    div[lay-id="agentAddDueTable"] .layui-table-body,
    div[lay-id="agentAddDueTable"] .layui-table-cell {
        overflow: visible;
        padding: 0 1px;
    }

    div[lay-id="agentAddDueTable"] .layui-table-cell {
        height: auto;
        padding: 0 10px;
        word-break: break-word;
        white-space: pre-line;
    }

    .subjectDetailBox > div {
        margin-right: 10px !important;
    }

    [lay-filter="agentAddDueForm"] .open-details-box::-webkit-scrollbar {
        display: none;
        width: 0;
    }
    .supplierInfoForm .layui-form-label{
        width: 90px;
    }
    .supplierInfoForm .layui-input-block{
        margin-left: 120px;
    }
    div[lay-id="agentAddDueTable"] .layui-table-tool{
        position: initial;
    }
</style>

<!-- 表格操作列 -->
<script type="text/html" id="supplierInfoTableBar">
    <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="edit">修改</a>
    <a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="details">详情</a>
    <a class="layui-btn layui-btn-xs" lay-event="due">尽调</a>
    <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="audit">审核</a>
    <!--<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="pact">合同</a>-->
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<!-- 表单弹窗 -->
<script type="text/html" id="supplierInfoForm">
    <form lay-filter="supplierInfoForm" class="layui-form model-form supplierInfoForm">
        <input name="id" type="hidden"/>
        <div class="layui-form-item layui-row">
            <div class="layui-col-md4">
                <label class="layui-form-label">公司名称</label>
                <div class="layui-input-block">
                    <input name="corporateName" placeholder="请输入供应商公司名称" type="text" class="layui-input"
                           lay-verify="required" required autocomplete="off"/>
                </div>
            </div>

          <!--  <div class="layui-col-md4" id="code">
                <label class="layui-form-label">供应商编码2</label>
                <div class="layui-input-block">
                    <input name="code" placeholder="请输入供应商编码" type="text" class="layui-input" autocomplete="off"/>
                </div>
            </div>-->
            <div class="layui-col-md4">
                <label class="layui-form-label">供应商编码</label>
                <div class="layui-input-block">
                    <input name="code" placeholder="请输入供应商编码" type="text" class="layui-input"
                           lay-verify="required" required autocomplete="off"/>
                </div>
            </div>


            <div class="layui-col-md4" style="display: flex;">
                <label class="layui-form-label">供应商级别</label>
                <div class="layui-input-block" style="margin: 0 10px 0 0; flex: 1;">
                    <select name="levelId" lay-verify="required" required id="levelId"></select>
                </div>
                <div class="layui-form-mid layui-word-aux" style="margin-right: 0;">
                    <a href="#/purchase/supplierLevel" class="layui-btn layui-btn-xs" ew-event="closeDialog">
                        <i class="layui-icon layui-icon-addition"></i>
                    </a>
                </div>
            </div>
        </div>
        <div class="layui-form-item layui-row">
            <div class="layui-col-md4" style="display: flex;">
                <label class="layui-form-label">供应商分类</label>
                <input name="categoryId" type="hidden" lay-verify="categoryId" lay-verify="required"/>
                <div class="layui-input-block" id="selectCategory" style="margin: 0 10px 0 0; flex: 1;">
                </div>
                <div class="layui-form-mid layui-word-aux" style="margin-right: 0;">
                    <a href="#/purchase/supplierCategory" class="layui-btn layui-btn-xs" ew-event="closeDialog">
                        <i class="layui-icon layui-icon-addition"></i>
                    </a>
                </div>
            </div>
            <div class="layui-col-md4">
                <label class="layui-form-label">证件号码</label>
                <div class="layui-input-block">
                    <input name="certificateNumber" placeholder="请输入证件号码" type="text" class="layui-input"
                           lay-verify="required" required autocomplete="off"/>
                </div>
            </div>
            <div class="layui-col-md4">
                <label class="layui-form-label">营业执照</label>
                <div class="layui-input-block">
                    <div id="btnUploadCredentials_path" class="uploadImgStyle"></div>
                    <div id="btnUploadCredentials" class="layui-btn" style="float: left;"><i class="layui-icon">&#xe681;</i>上传
                    </div>
                    <input name="certificatePic" type="hidden" class="layui-input" lay-verify="" id="certificatePic"/>
                </div>
            </div>
        </div>
        <div class="layui-form-item layui-row">
            <div class="layui-col-md4">
                <label class="layui-form-label">收款银行</label>
                <div class="layui-input-block">
                    <input name="bankName" placeholder="请输入收款银行" type="text" class="layui-input" autocomplete="off"
                    />
                </div>
            </div>
            <div class="layui-col-md4">
                <label class="layui-form-label">收款银行账户</label>
                <div class="layui-input-block">
                    <input name="bankAccount" placeholder="请输入收款银行账户" type="text" class="layui-input" autocomplete="off"
                    />
                </div>
            </div>
            <div class="layui-col-md4">
                <label class="layui-form-label">收款银行账号</label>
                <div class="layui-input-block">
                    <input name="bankNumber" placeholder="请输入收款银行账号" type="text" class="layui-input" autocomplete="off"
                    />
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">开户许可证</label>
            <div class="layui-input-block">
                <div id="btnUploadDviceAppendix_path" class="uploadImgStyle"></div>
                <div id="btnUploadDviceAppendix" class="layui-btn" style="float: left;"><i
                        class="layui-icon">&#xe681;</i>上传
                </div>
                <input name="openingPermitPic" type="hidden" class="layui-input" lay-verify="" id="openingPermitPic"/>
            </div>
        </div>
        <div class="layui-form-item layui-row">
            <div class="layui-col-md4">
                <label class="layui-form-label">省</label>
                <div class="layui-input-block">
                    <select name="provinceId" id="provinceId" lay-filter="provinceId"
                    ></select>
                </div>
            </div>
            <div class="layui-col-md4">
                <label class="layui-form-label">市</label>
                <div class="layui-input-block">
                    <select name="cityId" id="cityId" lay-filter="cityId" ></select>
                </div>
            </div>
            <div class="layui-col-md4">
                <label class="layui-form-label">区/县</label>
                <div class="layui-input-block">
                    <select name="areaId" id="areaId" lay-filter="areaId" ></select>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">联系地址</label>
            <div class="layui-input-block">
                <input name="contactAddress" placeholder="请输入联系地址" type="text" class="layui-input" autocomplete="off"
                       />
            </div>
        </div>
        <div class="layui-form-item layui-row">
            <div class="layui-col-md4">
                <label class="layui-form-label">业务联系人</label>
                <div class="layui-input-block">
                    <input name="businessContact" placeholder="请输入业务联系人" type="text" class="layui-input" autocomplete="off"
                    />
                </div>
            </div>
            <div class="layui-col-md4">
                <label class="layui-form-label">财务联系人</label>
                <div class="layui-input-block">
                    <input name="financialContact" placeholder="请输入财务联系人" type="text" class="layui-input" autocomplete="off"
                    />
                </div>
            </div>
            <div class="layui-col-md4">
                <label class="layui-form-label">法定代表人</label>
                <div class="layui-input-block">
                    <input name="legalPerson" placeholder="请输入法定代表人" type="text" class="layui-input" autocomplete="off"
                    />
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">备注描述</label>
            <div class="layui-input-block">
                <input name="remark" placeholder="请输入备注描述" type="text" class="layui-input" autocomplete="off"/>
            </div>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog" id="cancel">取消</button>
            <button class="layui-btn" lay-filter="supplierInfoFormSubmit" lay-submit id="supplierInfoFormSubmit">保存
            </button>
        </div>
    </form>
</script>


<!-- 尽调弹窗 -->
<script type="text/html" id="agentDueForm">
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">
                <!-- 头部操作栏 -->
                <div class="layui-form toolbar">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <button id="agentDueBtnAdd" class="layui-btn icon-btn">添加供应商尽调记录信息</button>
                        </div>
                    </div>
                </div>
                <!-- 表格 -->
                <table class="layui-table" id="agentDueTable" lay-filter="agentDueTable"></table>
            </div>
        </div>
    </div>
</script>

<!--尽调添加弹窗 -->
<script type="text/html" id="agentAddDueForm">
    <form lay-filter="agentAddDueForm" class="layui-form model-form"
          style="padding: 5px 30px 0 30px;height: calc(100% - 5px);overflow: hidden;">
        <div class="open-details-box"
             style="height: calc(100% - 70px);overflow: auto;margin-bottom: 15px;">
            <div class="layui-form-item">
                <table class="layui-table" id="agentAddDueTable" lay-filter="agentAddDueTable"
                       style="margin: 0"></table>
            </div>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button id="supplierDueFormSubmit" class="layui-btn" lay-filter="agentAddDueFormSubmit" lay-submit>保存
            </button>
        </div>
    </form>

    <!-- <form lay-filter="agentAddDueForm" class="layui-form model-form">
         <input name="id" type="hidden"/>
         <div class="layui-form-item">
             <label class="layui-form-label">供应商名称</label>
             <div class="layui-input-inline">
                 <select lay-filter="purSupId" id="purSupId" name="purSupId" lay-verify="required">
                     <option value="">请选择供应商</option>
                 </select>
             </div>
         </div>
         <div class="layui-form-item">
             <label class="layui-form-label">尽调类型</label>
             <input name="categoryId" value="" type="hidden">
             <div class="layui-input-inline mr0" id="categoryIdDue">
             </div>
         </div>
         <div class="layui-form-item">
             <label class="layui-form-label">尽调科目一</label>
             <div class="layui-input-inline">
                 <select lay-filter="subject1Id" id="subject1Id" name="subject1Id" lay-verify="required">
                     <option value="">请选择尽调科目</option>
                 </select>
             </div>
         </div>
         <div class="layui-form-item">
             <label class="layui-form-label">科目一评述</label>
             <div class="layui-input-block" id="subject1">
                 &lt;!&ndash;<textarea id="subject1Detail" name="subject1Detail" placeholder="请输入内容(200字以内)" class="layui-textarea"
                           maxlength="200"></textarea>&ndash;&gt;
             </div>
         </div>
         <div class="layui-form-item">
             <label class="layui-form-label">尽调科目二</label>
             <div class="layui-input-inline">
                 <select lay-filter="subject2Id" id="subject2Id" name="subject2Id" lay-verify="required">
                     <option value="">请选择尽调科目</option>
                 </select>
             </div>
         </div>
         <div class="layui-form-item">
             <label class="layui-form-label">科目二评述</label>
             <div class="layui-input-block" id="subject2">
               &lt;!&ndash;  <textarea id="subject2Detail" name="subject2Detail" placeholder="请输入内容(200字以内)" class="layui-textarea"
                           maxlength="200"></textarea>&ndash;&gt;
             </div>
         </div>
         <div class="layui-form-item">
             <label class="layui-form-label">尽调科目三</label>
             <div class="layui-input-inline">
                 <select lay-filter="subject3Id" id="subject3Id" name="subject3Id" lay-verify="required">
                     <option value="">请选择尽调科目</option>
                 </select>
             </div>
         </div>
         <div class="layui-form-item">
             <label class="layui-form-label">科目三评述</label>
             <div class="layui-input-block" id="subject3">
                 &lt;!&ndash;<textarea id="subject3Detail" name="subject3Detail" placeholder="请输入内容(200字以内)" class="layui-textarea"
                           maxlength="200"></textarea>&ndash;&gt;
             </div>
         </div>
         <div class="layui-form-item">
             <label class="layui-form-label">附件</label>
             <div id="btnUpload19" class="layui-btn" style="float: left;"><i class="layui-icon">&#xe681;</i>上传附件</div>
             <div id="btnUpload19_path" style="margin-left: 260px;line-height: 40px;"  ></div>
             <input id="fileUrl" name="fileUrl" type="hidden"/>
             <input id="fileName" name="fileName" type="hidden"/>
         </div>

         <div class="layui-form-item">
             <label class="layui-form-label">评估结果</label>
             <div class="layui-input-block">
                 <select name="result">
                     <option value="pass">符合且可以通过</option>
                     <option value="check">符合在考察考察</option>
                     <option value="waitPass">不符合但可以通过</option>
                     <option value="inconformity">不符合</option>
                 </select>
             </div>
         </div>
         <div class="layui-form-item">
             <label class="layui-form-label">整体评估描述</label>
             <div class="layui-input-block">
                 <textarea id="detail" name="detail" placeholder="请输入内容(200字以内)" class="layui-textarea"
                           maxlength="200"></textarea>
             </div>
         </div>
         <div class="layui-form-item text-right">
             <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
             <button id="supplierDueFormSubmit" class="layui-btn" lay-filter="agentAddDueFormSubmit" lay-submit>保存</button>
         </div>
     </form>-->
</script>

<!--尽调头部操作-->
<script type="text/html" id="agentAddDueFormToolbar">
    <a class="layui-btn" lay-event="agentAddDueFormToolbarAdd">添加</a>
</script>

<script type="text/html" id="agentAddDueTableBar">
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
</script>
<!-- 表格操作列 -->
<script type="text/html" id="agentDueTableBar">

    {{# if(d.status=='oncheck'){  }}
    <a class="layui-btn layui-btn-xs" lay-event="dueEdit">修改</a>
    <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="dueCheck">审核</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="dueDel">删除</a>
    {{# }else{ }}
    <a class="layui-btn layui-btn-xs" lay-event="dueDetail">详情</a>
    {{# } }}

</script>


<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'admin', 'upload', 'laydate'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var admin = layui.admin;
        var upload = layui.upload;
        var TreeData = [];
        var laydate = layui.laydate;

        // 渲染表格
        var insTb = table.render({
            elem: '#supplierInfoTable',
            url: config.base + 'enterprise/purchase/admin/supplierInfo/list?pageIndexName=1',
            toolbar: true,
            defaultToolbar: ["filter"],
            page: true,
            cellMinWidth: 100,
            cols: [[
                {type: 'numbers', title: '序号', fixed: 'left'}
                , {field: 'corporateName', sort: false, title: '供应商公司名称', fixed: 'left', width: 220}
                , {field: 'code', sort: true, title: '供应商编码', width: 120}
                , {field: 'categoryName', sort: false, title: '供应商分类'}
                , {field: 'sourceTypeDesc', sort: false, title: '来源'}
                , {field: 'remark', sort: false, title: '备注描述'}
                , {field: 'statusDesc', sort: false, title: '状态'}
                , {field: 'createTime', sort: false, title: '创建时间'}
                , {align: 'center', fixed: 'right', toolbar: '#supplierInfoTableBar', title: '操作', width: 310}
            ]],
        });

        var flag = true;
        // 工具条点击事件
        table.on('tool(supplierInfoTable)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') { //修改
                flag = false;
                showEditModel(data);
            } else if (obj.event === 'del') { // 删除
                doDelete(obj);
            } else if (obj.event === 'details') { // 详情
                flag = true;
                showEditModel(data);
            } else if (obj.event === 'audit') { // 审核
                doAudit(obj);
            } else if (obj.event === 'due') { // 尽调
                doDue(obj);
            }
        });


        //监听排序
        table.on('sort(supplierInfoTable)', function (obj) {
            table.reload('supplierInfoTable', {
                initSort: obj
                , where: {
                    sort: obj.field
                    , order: obj.type
                }
            });
        });

        // 添加按钮点击事件
        $('#supplierInfoBtnAdd').click(function () {
            showEditModel();
        });


        // 审核
        function doAudit(obj) {

                        layer.confirm('确定要审核吗？', {
                            offset: '65px',
                            skin: 'layui-layer-admin'
                        }, function (i) {
                            layer.close(i);
                            layer.load(2);
                            admin.req('enterprise/purchase/admin/supplierInfo/audit?id=' + obj.data.id, {}, function (res) {
                                layer.closeAll('loading');
                                if (res.code == 200) {
                                    layer.msg(res.msg, {icon: 1});
                                    insTb.reload();
                                } else {
                                    layer.msg(res.msg, {icon: 2});
                                }
                            }, 'GET');
                        });
        }




      /*  // 审核
        function doAudit(obj) {
            admin.req('enterprise/purchase/admin/supplierDue/list?purSupId=' + obj.data.id, {}, function (res) {
                if (res.data.length == 0) {
                    layer.confirm('该供应商还未添加尽调信息，请先添加', {
                        offset: '65px',
                        skin: 'layui-layer-admin'
                    })
                } else {
                    let count = 0;
                    for (let i = 0; i < res.data.length; i++) {
                        if (res.data[i].status != 'oncheck') {
                            count++;
                        }
                    }
                    if (count == res.data.length) {
                        layer.confirm('确定要审核吗？', {
                            offset: '65px',
                            skin: 'layui-layer-admin'
                        }, function (i) {
                            layer.close(i);
                            layer.load(2);
                            admin.req('enterprise/purchase/admin/supplierInfo/audit?id=' + obj.data.id, {}, function (res) {
                                layer.closeAll('loading');
                                if (res.code == 200) {
                                    layer.msg(res.msg, {icon: 1});
                                    insTb.reload();
                                } else {
                                    layer.msg(res.msg, {icon: 2});
                                }
                            }, 'GET');
                        });
                    } else {
                        layer.confirm('该供应商还有尽调信息未审核，请先审核', {
                            offset: '65px',
                            skin: 'layui-layer-admin'
                        })
                    }
                }
            }, 'GET')

        }*/


        // 显示编辑弹窗
        function showEditModel(data) {
            admin.open({
                type: 1,
                area: '1280px',
                offset: '65px',
                title: data ? (flag ? '详情' : '修改') : '添加供应商',
                content: $('#supplierInfoForm').html(),
                success: function () {
                    //自定义验证规则
                    form.verify({
                        categoryId: function (value) {
                            if (value == "") {
                                return "请选择供应商分类";
                            }
                        }
                    })
                    if (data && !flag) {//修改
                        admin.reqSync('enterprisecab/area/admin/area/getProvince', {}, function (res) {
                            if (200 == res.code) {
                                loadSelectHtml(res.data, "请选择省份", "provinceId", 0);
                            }
                        }, 'GET', true);

                        admin.reqSync('enterprisecab/area/admin/area/getCity?parentId=' + data.provinceId, {}, function (res) {
                            if (200 == res.code) {
                                loadSelectHtml(res.data, "请选择城市", "cityId", 0);
                            }
                        }, 'GET', true);

                        admin.reqSync('enterprisecab/area/admin/area/getArea?parentId=' + data.cityId, {}, function (res) {
                            if (200 == res.code) {
                                loadSelectHtml(res.data, "请选择区/县", "areaId", 0);
                            }
                        }, 'GET', true);

                        //供应商级别
                        admin.reqSync('enterprise/purchase/admin/supplierLevel/list?page=1&limit=9999', {}, function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                loadSelectHtml(res.data, "请选择供应商级别", "levelId", 0)
                            }
                        }, 'GET');

                        var selectArea = function (city) {
                            admin.req('enterprisecab/area/admin/area/getArea?parentId=' + city, {}, function (res) {
                                layer.closeAll('loading');
                                if (200 == res.code) {
                                    loadSelectHtml(res.data, "请选择区/县", "areaId", 0);
                                }
                            }, 'GET');
                        }
                        var selectCity = function (province) {
                            admin.req('enterprisecab/area/admin/area/getCity?parentId=' + province, {}, function (res) {
                                layer.closeAll('loading');
                                if (200 == res.code) {
                                    loadSelectHtml(res.data, "请选择市", "cityId", 0);
                                }
                            }, 'GET');
                        }

                        form.on('select(provinceId)', function (data) {
                            console.log("选择事件触发",data);
                            $("#cityId").empty();
                            $('#areaId').empty();

                            // 获取市区域信息
                            if (data.value != '') {
                                selectCity(data.value);
                            }
                        });

                        form.on('select(cityId)', function (data) {
                            $('#areaId').empty();

                            // 获取区县区域信息
                            if (data.value != '') {
                                selectArea(data.value);
                            }
                        });
                        //供应商分类
                        /* admin.reqSync('enterprise/purchase/admin/supplierCategory/list?page=1&limit=9999', {}, function (res) {
                             layer.closeAll('loading');
                             if (res.code == 200) {
                                 loadSelectHtml(res.data, "请选择供应商类别", "categoryId",0)
                             }
                         }, 'GET');*/
                        $("#btnUploadCredentials_path").html("<img src='" + data.certificatePic + "'/>")
                        $("#btnUploadDviceAppendix_path").html("<img src='" + data.openingPermitPic + "'/>")
                        layer.photos({
                            photos: '.uploadImgStyle'
                            , anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
                        });
                     /*   $('#code').css("display", "none")*/
                    } else if (data && flag) {//详情
                        admin.reqSync('enterprisecab/area/admin/area/getProvince', {}, function (res) {
                            if (200 == res.code) {
                                loadSelectHtml(res.data, "请选择省份", "provinceId", 0);
                            }
                        }, 'GET', true);

                        admin.reqSync('enterprisecab/area/admin/area/getCity?parentId=' + data.provinceId, {}, function (res) {
                            if (200 == res.code) {
                                loadSelectHtml(res.data, "请选择城市", "cityId", 0);
                            }
                        }, 'GET', true);

                        admin.reqSync('enterprisecab/area/admin/area/getArea?parentId=' + data.cityId, {}, function (res) {
                            if (200 == res.code) {
                                loadSelectHtml(res.data, "请选择区/县", "areaId", 0);
                            }
                        }, 'GET', true);


                        $("#btnUploadCredentials_path").html("<img src='" + data.certificatePic + "'/>")
                        $("#btnUploadDviceAppendix_path").html("<img src='" + data.openingPermitPic + "'/>")
                        layer.photos({
                            photos: '.uploadImgStyle'
                            , anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
                        });
                        $('[lay-filter="supplierInfoForm"] input').attr("disabled", '');
                        $('[lay-filter="supplierInfoForm"] input').attr("placeholder", ' ');
                        $('[lay-filter="supplierInfoForm"] select').attr("disabled", '');


                        $('#supplierInfoFormSubmit').css("display", "none")
                        $('#cancel').css("display", "none")
                        $('#btnUploadCredentials').css("display", "none")
                        $('#btnUploadDviceAppendix').css("display", "none")

                        loadSelectHtml(data, data.categoryName, "categoryId");
                        loadSelectHtml(data, data.levelName, "levelId");
                    } else if (!data) {//添加
                        $('#code').css("display", "none")
                        //供应商级别
                        admin.reqSync('enterprise/purchase/admin/supplierLevel/list?page=1&limit=9999', {}, function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                loadSelectHtml(res.data, "请选择供应商级别", "levelId", 0)
                            }
                        }, 'GET');
                        //供应商分类
                        /*admin.reqSync('enterprise/purchase/admin/supplierCategory/list?page=1&limit=9999', {}, function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                loadSelectHtml(res.data, "请选择供应商类别", "categoryId",0)
                            }
                        }, 'GET');*/
                        var selectArea = function (city) {
                            admin.req('enterprisecab/area/admin/area/getArea?parentId=' + city, {}, function (res) {
                                layer.closeAll('loading');
                                if (200 == res.code) {
                                    loadSelectHtml(res.data, "请选择区/县", "areaId", 0);
                                }
                            }, 'GET');
                        }
                        var selectCity = function (province) {
                            admin.req('enterprisecab/area/admin/area/getCity?parentId=' + province, {}, function (res) {
                                layer.closeAll('loading');
                                if (200 == res.code) {
                                    loadSelectHtml(res.data, "请选择市", "cityId", 0);
                                }
                            }, 'GET');
                        }
                        // 获取省区域信息
                        admin.req('enterprisecab/area/admin/area/getProvince', {}, function (res) {

                            if (200 == res.code) {
                                loadSelectHtml(res.data, "请选择省份", "provinceId", 0);
                            }
                        }, 'GET', true);

                        form.on('select(provinceId)', function (data) {
                            console.log("选择事件触发",data);
                            $("#cityId").empty();
                            $('#areaId').empty();

                            // 获取市区域信息
                            if (data.value != '') {
                                selectCity(data.value);
                            }
                        });

                        form.on('select(cityId)', function (data) {
                            $('#areaId').empty();

                            // 获取区县区域信息
                            if (data.value != '') {
                                selectArea(data.value);
                            }
                        });
                    }


                    var json = {};
                    if (data && data.categoryId) {
                        json.selectId = data.categoryId;
                    }

                    admin.reqSync('enterprise/purchase/admin/supplierCategory/getTreeData', json, function (obj) {
                        TreeData = obj.data;
                        xmSelect.render({
                            el: '#selectCategory',
                            model: {label: {type: 'text'}},
                            radio: true,
                            clickClose: true,
                            filterable: true,
                            tree: {
                                show: true,
                                strict: false,
                                expandedKeys: [-1],
                            },
                            tips: '顶级分类',
                            height: 'auto',
                            data() {
                                return TreeData;
                            },
                            on: function (data) {
                                //被选中的select的id,如果没有 -1
                                let categoryId = data.arr.length > 0 ? data.change[0].value : -1;
                                $("input[name='categoryId']").val(categoryId);
                            },
                        });
                    }, 'GET');

                    if (data && flag) {
                        xmSelect.render({
                            el: '#selectCategory',
                            disabled: true
                        })
                    }

                    form.val('supplierInfoForm', data);


                    $('#btnUploadCredentials').click(uploadImg('btnUploadCredentials', 'btnUploadCredentials_path', 'certificatePic'))
                    $('#btnUploadDviceAppendix').click(uploadImg('btnUploadDviceAppendix', 'btnUploadDviceAppendix_path', 'openingPermitPic'))

                    // 表单提交事件
                    form.on('submit(supplierInfoFormSubmit)', function (d) {
                        layer.load(2);
                        admin.req(data ? 'enterprise/purchase/admin/supplierInfo/update' : 'enterprise/purchase/admin/supplierInfo/add', d.field, function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('supplierInfoTable');
                                layer.closeAll('page');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, data ? 'PUT' : 'POST');
                        return false;
                    });
                }
            });
        }

        // 搜索
        form.on('submit(formSubSearchLog)', function (data) {
            insTb.reload({where: data.field, page: {curr: 1}}, 'data');
        });

        // 重置搜索
        form.on('submit(resets)', function (data) {
            insTb.reload({where: admin.resetSearch(data.field), page: {curr: 1}}, 'data');
        });

        // 删除
        function doDelete(obj) {
            layer.confirm('供应商的其他相关信息也将删除，确定要删除吗？', {
                offset: '65px',
                skin: 'layui-layer-admin'
            }, function (i) {
                layer.close(i);
                layer.load(2);
                admin.req('enterprise/purchase/admin/supplierInfo/' + obj.data.id, {}, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});
                        obj.del();
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'DELETE');
                insTb.reload();
            });
        }


        // 上传
        function uploadImg(_elem, pathId, inputId, inputName) {
            upload.render({
                elem: '#' + _elem
                , url: config.upload_url + 'uploadFile'
                , data: {}
                , accept: 'file'
                , exts: 'jpg|png|RAR|zip|pdf|txt|doc|docx|xls|xlsx|ppt|pptx'
                , headers: {Authorization: 'Bearer ' + config.getToken()}
                , done: function (res) {
                    if (res.code == 200) {
                        layer.msg(res.msg || "上传成功", {icon: 1});
                        let imagUrl = res.data.url;
                        $('#' + pathId).html('<img src="' + imagUrl + '"/>');
                        $('#' + inputId).val(imagUrl);
                        if (inputName) {
                            $('#' + pathId).html('<span>' + imagUrl.split('/')[imagUrl.split('/').length - 1] + '</span>');
                            $('#' + inputName).val(imagUrl.split('/')[imagUrl.split('/').length - 1]);
                        }
                    } else if (res.code == 502) {
                        return location.replace('admin/login.html');
                    } else {
                        layer.msg(res.msg || "上传失败", {icon: 2});
                    }
                }
            });
        }


        // option渲染
        function loadSelectHtml(data, tips, htmltarget, type) {
            let html = ' <option value>' + tips + '</option>';
            if (!data || data == null) {
                return;
            }
            for (let i = 0; i < data.length; i++) {
                if (type === 0) {
                    html += `<option value='${data[i].id}'>${data[i].name}</option>`;
                } else if (type === 1) {
                    html += `<option value='${data[i].id}'>${data[i].corporateName}</option>`;
                }
            }

            $("form select[name='" + htmltarget + "']").html(html);
            form.render('select');
        }

        var dueFlag = true;

        //尽调
        function doDue(obj) {
            admin.open({
                type: 1,
                area: ['85%', '85%'],
                offset: '65px',
                title: '供应商尽调管理',
                content: $('#agentDueForm').html(),
                success: function () {
                    var contcactsTb = table.render({
                        elem: '#agentDueTable',
                        url: config.base + 'enterprise/purchase/admin/supplierDue/list?purSupId=' + obj.data.id,
                        page: true,
                        cellMinWidth: 100,
                        cols: [[
                            {type: 'numbers', title: '序号'}
                            , {field: 'code', sort: true, title: '尽调编号'}
                            , {field: 'categoryName', sort: false, title: '尽调类型'}
                            , {field: 'subjectName', sort: false, title: '科目名称'}
                            , {field: 'resultDesc', sort: false, title: '尽调结果'}
                            , {field: 'statusDesc', sort: false, title: '状态'}
                            , {field: 'createTime', sort: false, title: '录入时间'}
                            , {field: 'auditor', sort: true, title: '审核人'}
                            , {field: 'auditTime', sort: false, title: '审核时间'}
                            , {align: 'center', toolbar: '#agentDueTableBar', title: '操作', width: 200}
                        ]],
                    });
                    // 尽调添加按钮点击事件
                    $('#agentDueBtnAdd').click(function () {
                        dueFlag = false;
                        showDueEditModel(obj);
                    });
                }
            })
        }

        // 显示编辑尽调弹窗
        function showDueEditModel(obj, data) {
            var index = admin.open({
                type: 1,
                area: ['80%', '80%'],
                offset: '85px',
                title: data ? (dueFlag ? '修改供应商尽调记录' : '详情') : '添加供应商尽调记录',
                content: $('#agentAddDueForm').html(),
                success: function () {
                    let agentAddDueTableData = [];

                    //加载供应商列表
                    admin.req('enterprise/purchase/admin/supplierInfo/list', {limit: 99999}, function (res) {
                        loadSelectHtml(res.data, "请选择供应商", "purSupId", 1);
                        if (obj && !dueFlag) {
                            $("#purSupId").html("<option>" + obj.data.corporateName + "</option>");
                            $("#purSupId").attr("disabled", '');
                            form.render('select');
                        }
                    }, 'get', false);

                    //加载尽调分类
                    var arr2tree;
                    admin.reqSync('enterprise/purchase/admin/supplierDueSubjectCategory/list', {limit: 99999}, function (res) {
                        for (let i = 0; i < res.data.length; i++) {
                            res.data[i].children = [];
                        }
                        arr2tree = xmSelect.arr2tree(res.data, "parentId", "id", "children", -1);
                    }, 'get');

                    var selectedData = function (treeData, targetId) {
                        for (var k = 0; k < treeData.length; k++) {
                            var nodeId = treeData[k].id;
                            if (targetId == nodeId) {
                                treeData[k].selected = true;
                                return;
                            } else {
                                if (treeData[k].children && treeData[k].children != '') {
                                    selectedData(treeData[k].children, targetId);
                                }
                            }
                        }
                    };

                    if (data) {
                        selectedData(arr2tree, data.categoryId);
                        //加载尽调科目
                        admin.reqSync('enterprise/purchase/admin/supplierDueSubject/list', {
                            limit: 99999,
                            subId: data.categoryId
                        }, res => {
                            if (res.code === 200) {
                                data.subjectIdData = res.data;
                                res.data.forEach(item => {
                                    if (item.id == data.subjectId) {
                                        data.subjectDetailData = item.paramValue.split(',')
                                    }
                                })
                            } else {
                                data.subjectIdData = [];
                                data.subjectDetailData = [];
                            }
                        }, 'get', false);
                        data.categoryIdData = arr2tree;
                        data.subjectDetailArr = [];
                        data.index = 0;
                        agentAddDueTableData = [data];

                    }

                    var agentAddDueTb = table.render({
                        elem: '#agentAddDueTable',
                        data: agentAddDueTableData,
                        toolbar: data ? '' : '#agentAddDueFormToolbar',
                        totalRow: false,
                        defaultToolbar: [],
                        page: false,
                        limit: Number.MAX_VALUE,
                        cellMinWidth: 100,
                        cols: [[
                            {
                                field: 'categoryId',
                                title: '尽调分类',
                                templet: d => '<input type="hidden" id="categoryId' + d.index + '" /> <div class="categoryIdDataBox" id="categoryIdData' + d.index + '"></div>'
                            }
                            , {
                                field: 'subjectId', title: '尽调科目', templet: d => {
                                    let selectHTML = '<select name="subjectId" lay-filter="subjectId" lay-verify="required">';
                                    selectHTML += '<option value="">请选择</option>';
                                    d.subjectIdData.forEach((item, index) => {
                                        if (item.id === d.subjectId) {
                                            selectHTML += `<option value="${item.id}" type="${item.type}" data="${item.paramValue}" selected="">${item.name}</option>`;
                                        } else {
                                            selectHTML += `<option value="${item.id}" type="${item.type}" data="${item.paramValue}">${item.name}</option>`;
                                        }
                                    });
                                    selectHTML += '</select>';
                                    return selectHTML
                                }
                            }
                            , {
                                field: 'subjectDetail', title: '尽调评述', width: 300, templet: d => {
                                    let subjectDetailHtml = '<div class="subjectDetailBox">';
                                    if (d.subjectType == 'radio') {
                                        d.subjectDetailData.forEach((item, index) => {
                                            if (item == d.subjectDetail) {
                                                subjectDetailHtml += '<input type="radio" class="subjectType" name="subjectDetail' + d.index + '" title="' + item + '" value="' + item + '" checked lay-verify="otherReq">'
                                            } else {
                                                subjectDetailHtml += '<input type="radio" class="subjectType" name="subjectDetail' + d.index + '" title="' + item + '" value="' + item + '" lay-verify="otherReq">'
                                            }
                                        });

                                    } else if (d.subjectType == 'check') {
                                        let subjectDetailArr = d.subjectDetail;
                                        d.subjectDetailData.forEach((item, index) => {
                                            subjectDetailHtml += '<div style="display: inline" class="subjectDetailBoxList">';
                                            if (subjectDetailArr.includes(item)) {
                                                subjectDetailHtml += '<input type="checkbox" class="subjectType" title="' + item + '"  name="subjectDetail' + d.index + '"  value="' + item + '" checked lay-verify="otherReq">';
                                            } else {
                                                subjectDetailHtml += '<input type="checkbox" class="subjectType" title="' + item + '"  name="subjectDetail' + d.index + '"  value="' + item + '" lay-verify="otherReq" >';
                                            }
                                            subjectDetailHtml += '</div>'
                                        });

                                    } else if (d.subjectType == 'text') {
                                        subjectDetailHtml += '<input type="text" class="layui-input subjectType" value="' + d.subjectDetail + '" lay-verify="required">'
                                    } else if (d.subjectType == 'date') {
                                        subjectDetailHtml += '<input type="text" class="layui-input subjectType" id="subjectType' + d.index + '" readonly lay-verify="required">'
                                    } else if (d.subjectType == 'time') {
                                        subjectDetailHtml += '<input type="text" class="layui-input subjectType" id="subjectType' + d.index + '" readonly lay-verify="required">'
                                    } else {
                                        subjectDetailHtml += ''
                                    }
                                    subjectDetailHtml += '</div>';
                                    return subjectDetailHtml
                                }
                            }
                            , {
                                field: 'enclosure',
                                title: '附件', width: 80, align: 'center', templet: d => {
                                    let btnHTML = '';
                                    if (!data || dueFlag) {
                                        btnHTML += `<a class="layui-btn layui-btn-xs" lay-event="uploadEnclosure">${d.enclosure ? '更改附件' : '上传附件'}</a><br/>`;
                                    }
                                    if (d.enclosure) {
                                        btnHTML += '<a class="layui-btn layui-btn-xs layui-btn-warm" href="' + d.enclosure + '" target="view_window">查看附件</a>';
                                    }

                                    return btnHTML;
                                }
                            }
                            , {
                                field: 'result', title: '结果', templet: d => {
                                    let selectHTML = '<select name="result" lay-filter="result" lay-verify="required">';
                                    selectHTML += `<option value="pass" ${d.result == "pass" ? "selected" : ""}>符合且可以通过</option>`;
                                    selectHTML += `<option value="check" ${d.result == "check" ? "selected" : ""}>符合在考察考察</option>`;
                                    selectHTML += `<option value="waitPass" ${d.result == "waitPass" ? "selected" : ""}>不符合但可以通过</option>`;
                                    selectHTML += `<option value="inconformity" ${d.result == "inconformity" ? "selected" : ""}>不符合</option>`;
                                    selectHTML += '</select>';
                                    return selectHTML
                                }
                            }
                            , {
                                field: 'detail',
                                title: '整体评估描述',
                                templet: d => '<input type="text" name="detail" class="layui-input" value="' + d.detail + '">'
                            },
                            data ? "" : {align: 'center', toolbar: '#agentAddDueTableBar', title: '操作', width: 100}
                        ]],
                        done: function (res, curr, count) {
                            if (count > 0) {
                                $('button[lay-filter="agentAddDueFormSubmit"]').show({duration: 300})
                            } else {
                                $('button[lay-filter="agentAddDueFormSubmit"]').hide({duration: 300})
                            }
                            for (let i = 0; i < res.data.length; i++) {
                                xmSelect.render({
                                    el: '#categoryIdData' + agentAddDueTableData[i].index,
                                    model: {label: {type: 'text'}},
                                    radio: true,
                                    initValue: [agentAddDueTableData[i].categoryId],
                                    layVerify: 'required',
                                    disabled: data ? (dueFlag ? false : true) : false,
                                    clickClose: true,
                                    filterable: true,
                                    tree: {
                                        show: true,
                                        strict: false,
                                        expandedKeys: [-1],
                                    },
                                    tips: '尽调分类',
                                    prop: {
                                        name: 'name',
                                        value: 'id',
                                        children: 'children'
                                    },
                                    data() {
                                        //填充数据

                                        return JSON.parse(JSON.stringify(agentAddDueTableData[i].categoryIdData));

                                    },
                                    on(data) {
                                        let parentId = data.change[0].id || '';
                                        $("#categoryId" + i).val(parentId);
                                        agentAddDueTableData[i].categoryId = parentId;
                                        console.log(agentAddDueTableData[i].categoryId)
                                        agentAddDueTableData[i].subjectType = '';
                                        agentAddDueTableData[i].subjectId = '';
                                        agentAddDueTableData[i].subjectDetail = '';
                                        //加载尽调科目
                                        admin.req('enterprise/purchase/admin/supplierDueSubject/list', {
                                            limit: 99999,
                                            subId: parentId
                                        }, function (res) {
                                            if (res.code === 200) {
                                                agentAddDueTableData[i].subjectIdData = res.data;
                                            } else {
                                                agentAddDueTableData[i].subjectIdData = [];
                                            }

                                            table.reload('agentAddDueTable', {data: agentAddDueTableData});

                                        }, 'get', false);
                                    }
                                });

                                upload.render({
                                    elem: $('div[lay-id="agentAddDueTable"]').find('[lay-event="uploadEnclosure"]').eq(i)
                                    , url: config.upload_url + 'uploadFile' //上传接口
                                    , data: {}
                                    , accept: 'file'
                                    , exts: 'jpg|png|RAR|zip|pdf|txt|doc|docx|xls|xlsx|ppt|pptx|apk'
                                    , headers: {Authorization: 'Bearer ' + config.getToken()}
                                    , done: function (res) {
                                        if (res.code == 200) {
                                            layer.msg(res.msg || "上传成功", {icon: 1});
                                            let imgObj = {
                                                fileUrl: res.data.url,
                                                fileName: res.data.fileName
                                            };
                                            agentAddDueTableData[this.elem.parents('tr').index()].enclosure = res.data.url;
                                            table.reload('agentAddDueTable', {data: agentAddDueTableData});
                                        } else if (res.code == 502) {
                                            return location.replace('admin/login.html');
                                        } else {
                                            layer.msg(res.msg || "上传失败", {icon: 2});
                                        }
                                    }
                                });

                                if (agentAddDueTableData[i].subjectType == 'date') {
                                    laydate.render({
                                        elem: '#subjectType' + agentAddDueTableData[i].index,
                                        type: 'date',
                                        index: res.data[i].index,
                                        value: res.data[i].subjectDetail,
                                        done: function (value, date) {
                                            agentAddDueTableData[this.index].subjectDetail = value;
                                        }
                                    });
                                } else if (agentAddDueTableData[i].subjectType == 'time') {
                                    laydate.render({
                                        elem: '#subjectType' + agentAddDueTableData[i].index,
                                        type: 'time',
                                        index: res.data[i].index,
                                        value: res.data[i].subjectDetail,
                                        done: function (value, date) {
                                            agentAddDueTableData[this.index].subjectDetail = value;
                                        }
                                    });
                                }
                            }

                            if (!dueFlag && data) {
                                $('div[lay-id="agentAddDueTable"] input').attr('disabled', 'disabled');
                                $('div[lay-id="agentAddDueTable"] select').attr('disabled', 'disabled');
                                $('button[lay-filter="agentAddDueFormSubmit"]').hide({duration: 300});
                                form.render('select');

                            }
                        }
                    });

                    //监听头工具栏事件
                    table.on('toolbar(agentAddDueTable)', function (_obj) {
                        if (_obj.event === 'agentAddDueFormToolbarAdd') { //添加
                            _obj.event = null;

                            let objData = {};
                            objData.index = agentAddDueTableData.length;
                            objData.purSupId = obj.data.id;
                            objData.categoryIdData = arr2tree; //JSON.parse(JSON.stringify(arr2tree)); // 尽调分类
                            objData.categoryId = ''; // 尽调分类

                            objData.subjectIdData = []; // 尽调科目
                            objData.subjectId = '';
                            objData.subjectType = '';

                            objData.subjectDetail = ''; // 尽调评述  （单选，多选，文本框,时间选择、日期选择）
                            objData.subjectDetailArr = []; // 复选框选择的值
                            objData.subjectDetailData = [];

                            objData.result = 'pass'; // 	结果
                            objData.resultData = '';// 结果数据

                            objData.enclosure = ''; // 	 附件
                            objData.detail = ''; // 整体评估描述
                            agentAddDueTableData.push(objData);
                            table.reload('agentAddDueTable', {data: agentAddDueTableData});
                        }
                    });

                    // 工具条点击事件
                    table.on('tool(agentAddDueTable)', function (obj) {
                        let data = obj.data;
                        if (obj.event === 'del') { // 删除
                            agentAddDueTableData.splice(obj.tr.index(), 1);
                            table.reload('agentAddDueTable', {data: agentAddDueTableData});
                        }
                    });

                    form.on("select", function (data) {
                        if ($(data.elem).attr('name') == 'subjectId') {
                            if (data.value && data.value != '') {
                                agentAddDueTableData[$(data.elem).parents('tr').index()].subjectId = data.value;
                                agentAddDueTableData[$(data.elem).parents('tr').index()].subjectType = $(data.elem).find("option:selected").attr("type");
                                agentAddDueTableData[$(data.elem).parents('tr').index()].subjectDetailData = $(data.elem).find("option:selected").attr("data").split(',');
                            } else {
                                agentAddDueTableData[$(data.elem).parents('tr').index()].subjectId = '';
                                agentAddDueTableData[$(data.elem).parents('tr').index()].subjectType = '';
                                agentAddDueTableData[$(data.elem).parents('tr').index()].subjectDetailData = [];
                            }
                            agentAddDueTableData[$(data.elem).parents('tr').index()].subjectDetail = '';
                            table.reload('agentAddDueTable', {data: agentAddDueTableData});
                        } else if ($(data.elem).attr('name') == 'result') {
                            agentAddDueTableData[$(data.elem).parents('tr').index()].result = data.value;
                        }
                    });

                    // 尽调评述 操作（复选框）
                    form.on('checkbox', function (data) {
                        if ($(data.elem).attr('class') == 'subjectType') {
                            if (data.elem.checked) {
                                agentAddDueTableData[$(data.elem).parents('tr').index()].subjectDetailArr[$(data.elem).parents('.subjectDetailBoxList').index()] = data.value;
                            } else {
                                agentAddDueTableData[$(data.elem).parents('tr').index()].subjectDetailArr[$(data.elem).parents('.subjectDetailBoxList').index()] = '';
                            }
                            agentAddDueTableData[$(data.elem).parents('tr').index()].subjectDetail = '';
                            agentAddDueTableData[$(data.elem).parents('tr').index()].subjectDetailArr.forEach(item => {
                                if (item) {
                                    agentAddDueTableData[$(data.elem).parents('tr').index()].subjectDetail += item + ','
                                }
                            });
                            agentAddDueTableData[$(data.elem).parents('tr').index()].subjectDetail = agentAddDueTableData[$(data.elem).parents('tr').index()].subjectDetail.substring(0, agentAddDueTableData[$(data.elem).parents('tr').index()].subjectDetail.length - 1);
                        }

                    });

                    // 尽调评述 操作（单选框）
                    form.on('radio', function (data) {
                        if ($(data.elem).attr('class') == 'subjectType') {
                            agentAddDueTableData[$(data.elem).parents('tr').index()].subjectDetail = data.value;
                        }

                    });

                    // 尽调评述 操作（输入文本框）
                       $("body").delegate("[lay-id='agentAddDueTable'] .subjectDetailBox input.subjectType", "change", function () {
                           if (agentAddDueTableData[$(this).parents('tr').index()]) {
                               agentAddDueTableData[$(this).parents('tr').index()].subjectDetail = $(this).val().trim();

                           }
                       });

                       $("body").delegate("[lay-id='agentAddDueTable'] input[name='detail']", "change", function () {
                           if (agentAddDueTableData[$(this).parents('tr').index()]) {
                               agentAddDueTableData[$(this).parents('tr').index()].detail = $(this).val().trim();
                           }
                       });

                       form.on('submit(agentAddDueFormSubmit)', function (d) {
                           if (agentAddDueTableData.length == 0) {
                               layer.msg('请添加记录', {icon: 5});
                               return false;
                           }
                           admin.req(data ? 'enterprise/purchase/admin/supplierDue/update' : 'enterprise/purchase/admin/supplierDue/addList', data ? JSON.stringify(agentAddDueTableData[0]) : JSON.stringify(agentAddDueTableData), res => {
                               if (res.code === 200) {
                                   layer.msg(res.msg, {icon: 1});
                                   table.reload('agentDueTable');
                                   layer.close(index);
                               } else {
                                   layer.msg(res.msg, {icon: 2});
                               }
                           }, data ? 'PUT' : 'POST', true, 'application/json; charset=utf-8');
                           return false;
                       })
                }

            })
        }


        //尽调工具条点击事件
        table.on('tool(agentDueTable)', function (obj) {
            var data = obj.data;
            if (obj.event === 'dueEdit') { //修改
                dueFlag = true;
                showDueEditModel(null, data);
            } else if (obj.event === 'dueDel') { // 删除
                doDueDelete(obj);
            } else if (obj.event === 'dueCheck') { // 审核
                doDueCheck(obj);
            } else if (obj.event === 'dueDetail') { // 详情
                dueFlag = false;
                showDueEditModel(null, data);
            }
        });

        // 尽调删除
        function doDueDelete(obj) {
            layer.confirm('确定要删除吗？', {
                offset: '65px',
                skin: 'layui-layer-admin'
            }, function (i) {
                layer.close(i);
                layer.load(2);
                admin.req('enterprise/purchase/admin/supplierDue/' + obj.data.id, {}, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});
                        obj.del();
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'DELETE');
            });
        }

        // 尽调审核
        function doDueCheck(obj) {
            layer.confirm('确定要审核吗？', {
                offset: '65px',
                btn: ['通过', '不通过'],
                skin: 'layui-layer-admin'
            }, function (i) {
                layer.close(i);
                layer.load(2);
                admin.req('enterprise/purchase/admin/supplierDue/check', JSON.stringify({
                    id: obj.data.id,
                    status: 'pass'
                }), res => {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});
                        table.reload('agentDueTable');
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'put', true, 'application/json; charset=utf-8');
            }, function (i) {
                layer.close(i);
                layer.load(2);
                admin.req('enterprise/purchase/admin/supplierDue/check', JSON.stringify({
                    id: obj.data.id,
                    status: 'noPass'
                }), res => {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});
                        table.reload('agentDueTable');
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'put', true, 'application/json; charset=utf-8');
            });
        }

        // 导出excel
        $('#supplierInfoBtnExport').click(function () {
            var checkRows = table.checkStatus('supplierInfoTable');
            if (checkRows.data.length == 0) {
                layer.msg('请选择要导出的数据', {icon: 2});
            } else {
                table.exportFile(insTb.config.id, checkRows.data, 'xls');
            }
        });

        //自定义验证（单选、复选框）
        form.verify({
            otherReq: function (value, item) {
                var verifyName = $(item).attr('name')
                    , verifyType = $(item).attr('type')
                    , formElem = $(item).parents('.layui-form')//获取当前所在的form元素，如果存在的话
                    , verifyElem = formElem.find("input[name='" + verifyName + "']")//获取需要校验的元素
                    , isTrue = verifyElem.is(':checked')//是否命中校验
                    , focusElem = verifyElem.next().find('i.layui-icon');//焦点元素
                if (!isTrue || !value) {
                    //定位焦点
                    focusElem.css(verifyType == 'radio' ? {"color": "#FF5722"} : {"border-color": "#FF5722"});
                    //对非输入框设置焦点
                    focusElem.first().attr("tabIndex", "1").css("outline", "0").blur(function () {
                        focusElem.css(verifyType == 'radio' ? {"color": ""} : {"border-color": ""});
                    }).focus();
                    return '必填项不能为空';
                }
            }
        });

    });
</script>